package ModelLayer;

import java.util.ArrayList;

public class AdressBook
{
    public ArrayList<Person>adressBook;
    private static AdressBook instance = null;
    
    public AdressBook()
    {
        adressBook = new ArrayList<Person>();
    }
    
    public static AdressBook getInstance() {
        if (instance == null) {
            instance = new AdressBook();
        }
        return instance;
    }
    
    public void addPerson(Person newPerson)
    {
        adressBook.add(newPerson);
    }
    
    public void deletePerson(Person delPerson)
    {
        adressBook.remove(delPerson);
    }
    
    public Person findPerson(int id) {
        int i = 0;
        Person result = null;
        boolean found = false;
        while (i < adressBook.size() && !found) {
            if (adressBook.get(i).getPersonId()== id) {
                result = adressBook.get(i);
                found = true;
            }
            i++;
        }
        return result;
    }
    
    
    public ArrayList<Person>getAll() {
        return adressBook;
    }
   
}
